"""
故障信息采集卡和FMEA采集卡中的数据模型
@Time: 2021/2/6 1:30
@Author:
@File: card_data_model.py
"""
from datetime import datetime
from typing import Optional, List

from pydantic import BaseModel, Field

fault_card_sections = ['故障描述', '分析过程', '故障定位', '处理措施及结果']
fmea_card_sections = ['故障原因', '故障检测方法', '故障检测方法']

class BaseCollectedCardDataModel(BaseModel):
    """
    采集卡的数据模型基类
    """
    brief: str = Field(title='信息简介',
                       description='不直接对应于采集卡的某一字段，需要根据采集卡的信息来单独生成该字段值')
    upload_time: datetime = Field(title='上传时间',
                                  default_factory=datetime.now)
    query_count: int = Field(title='查询次数计数',
                             default=0, ge=-2**63, lt=2**63)
    marked_proc: List[str] = Field(title='标记的进度',
                                   description='已完成标记部分的标题将存于该处',
                                   default_factory=list)
    data_source_type: int = Field(title='数据源类型',
                                  description='1 故障信息采集卡，2 FMEA 卡',
                                  ge=1, le=2)


class FaultInfoCardDataModel(BaseCollectedCardDataModel):
    """
    一张故障信息采集卡中的数据
    """
    unmarked_proc: List[str] = Field(title='未标记的进度',
                                     description='未被标记部分的标题将存于该处',
                                     default_factory=fault_card_sections.copy)
    fault_name: str = Field(title='故障名称', default='')
    fault_time: Optional[datetime] = Field(description='故障时间', default=None)
    fault_site: str = Field(title='故障地点', default='')


class FmeaCardDataModel(BaseCollectedCardDataModel):
    """
    一张 FMEA 卡中的数据
    """
    unmarked_proc: List[str] = Field(title='未标记的进度',
                                     description='未被标记部分的标题将存于该处',
                                     default_factory=fmea_card_sections.copy)
    code: str = Field(title='代码')
    project_func_name: str = Field(title='项目功能名称')
    task_stage: str = Field(title='任务阶段')
    faulty_mode: str = Field(title='故障模式')

